package com.chief.dubboFeign.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chief.dubboFeign.DubboTestService;
import com.chief.dubboFeign.entity.ProductEntity;
import com.chief.dubboFeign.entity.SexEnum;
import com.chief.dubboFeign.mapper.ProductMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class DubboTestServiceImpl extends ServiceImpl<ProductMapper, ProductEntity> implements DubboTestService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public String getName() {
        this.productMapper.insert(ProductEntity.builder().name("李四").sex(SexEnum.MAN).build());
        System.out.println("========================");

        QueryWrapper<ProductEntity> wrapper = new QueryWrapper<>();
        wrapper.ne("id",1);
        List<ProductEntity> productEntities = this.productMapper.selectList(wrapper);
        for (ProductEntity productEntity : productEntities) {
            System.out.println(productEntity.toString());
        }
        System.out.println("========================");

        this.productMapper.delete(wrapper);
        System.out.println("========================");

        productEntities = this.productMapper.selectList(null);
        for (ProductEntity productEntity : productEntities) {
            System.out.println(productEntity.toString());
        }
        System.out.println("========================");

        ProductEntity productEntity = super.getById(1);
        return "DubboTestServiceImpl getName "+productEntity.toString();
    }

}
